package com.sjc.cat.rule.servise.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sjc.cat.rule.domain.Charge;
import com.sjc.cat.rule.servise.ChargeRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @Author: pineee
 * @CreateTime: 2023-10-19 15:07
 * @Version: 1.0.0
 */
@Service
@Slf4j
public class ChargeRuleServiceImpl implements ChargeRuleService {

    //这里写死每公里的价钱为5元
    private static final double FEE_PER_MILEAGE = 5;
    /*
     * @author: pineee
     * @param: [mileage: 代驾里程, time：代驾开始时间, temp：不知道啥参数, key：不知道啥参数]
     * @return: java.util.HashMap
     *
     * 计算代驾费用
     * 这个接口是自己写的，计算法加费用的规则是最基本的 公里×每公里价钱
     * 没有其他复杂的规则
     **/
    @Override
    public HashMap calculateOrderCharge(String mileage, String time, int temp, Object key) {

        Double mileage2 = Double.valueOf(mileage);


        //要保留两位小数
        double fee = mileage2 * FEE_PER_MILEAGE;
        fee = Math.ceil(((fee) * 100)) / 100D;

        Charge charge = new Charge();
        charge.setAmount(fee+"");
        charge.setBaseMileage(mileage);
        charge.setBaseMileagePrice(FEE_PER_MILEAGE+"");
        charge.setExceedMileagePrice("1");
        charge.setMileageFee(fee+"");

        charge.setBaseMinute("1");
        charge.setExceedMinutePrice("1");
        charge.setWaitingFee("1");

        charge.setBaseReturnMileage("1");
        charge.setExceedReturnPrice("1");
        charge.setReturnMileage("1");
        charge.setReturnFee("1");

        HashMap map = (HashMap) BeanUtil.beanToMap(charge);

        return map;
    }
}
